local HY = require "packages.touhou_hy.utility.utility"
local U = require "packages.utility.utility"
local extension = Package:new("touhou_live")
extension.extensionName = "touhou_hy"

Fk:loadTranslationTable {
    ["touhou_live"] = "幻想生活",
}
---@diagnostic disable: inject-field
Skill.Genetics = "Genetics" --遗传技
---@diagnostic enable: inject-field

local continue_genetics = fk.CreateSkill {
    name = "continue_genetics"
}
continue_genetics:addEffect(fk.Death, {
    global = true,
    priority = 0.01,
    can_refresh = function(self, event, target, player, data)
        return player == target and table.any(player:getSkillNameList(), function(name)
            return Fk.skills[name]:hasTag(Skill.Genetics)
        end)
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local targets = room:askToChoosePlayers(player, {
            targets = room:getOtherPlayers(player),
            min_num = 1,
            max_num = 1,
            skill_name = continue_genetics.name,
            prompt = "continue_genetics_prompt",
        })
        if #targets ~= 1 then
            return
        end
        local skills = {}
        for _, name in ipairs(table.filter(player:getSkillNameList(), function(name)
            return Fk.skills[name]:hasTag(Skill.Genetics)
        end)) do
            table.insertIfNeed(skills, name)
        end
        local result = room:askToChoice(player, {
            choices = skills,
            skill_name = continue_genetics.name
        })
        room:setPlayerMark(targets[1], result .. "_mutation", 1)
        room:handleAddLoseSkills(targets[1], result)
    end
})
extension:loadSkillSkels { continue_genetics }
Fk:loadTranslationTable {
    ["continue_genetics"] = "遗传技",
    ["genetics_skill"] = "有遗传技的角色死亡时，可以令一名角色获得其中一个遗传技。以此法获得的遗传技会在基础效果之上触发突变。",
    ["continue_genetics_prompt"] = "你可以令一名角色获得你的一个遗传技",
}

local function loadGeneral(name)
    require("packages.touhou_hy.pkgs.live.generals." .. name)(extension, HY, U)
end

loadGeneral("hy_usami_renko")
loadGeneral("hy_maeriberii")
loadGeneral("hy_kamishirasawa_keine")
loadGeneral("hy_yakumo_ran")
loadGeneral("hy_letty_whiterock")
loadGeneral("hy_sekibanki")

return extension
